package it.cast.wechat.cotroller;

import it.cast.wechat.dto.Result;
import it.cast.wechat.pojo.Address;
import it.cast.wechat.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class AddressController {

    @Autowired
    private AddressService addressService;

    @RequestMapping("wx/address/queryAddressByUserId")
    @ResponseBody
    public List<Address> sellerList(String userId){
        return addressService.queryAddressByUserId(userId);
    }

    @RequestMapping("wx/address/queryAddressByAddressId")
    @ResponseBody
    public Address queryAddressByAddressId(String addressId){
        return addressService.queryAddressByAddressId(addressId);
    }

    @RequestMapping("wx/address/addressModify")
    @ResponseBody
    public Result<Integer> queryAddressByAddressId(@RequestBody Address address){
        Result<Integer> result = new Result<>();
        int state = 0;
        try {
            state = addressService.addressModify(address);
        }catch (Exception e){

        }
        result.setData(state);
        return result;
    }

    @RequestMapping("wx/address/deleteAddressById")
    @ResponseBody
    public Result<Integer> deleteAddressById(String addressId){
        Result<Integer> result = new Result<>();
        int state = 0;
        try {
            addressService.deleteAddressById(addressId);
        }catch (Exception e){
            state = 1;
        }
        result.setData(state);
        return result;
    }
}
